package qqclient.view;

import qqclient.service.UserClientService;
import utils.Utility;

//显示界面
public class QQView {
    private boolean loop = true;//控制一级菜单是否循环
    private UserClientService userClientService = new UserClientService();//用于登录和注册等客户端服务


    public void mainMenu() {
        while (loop) {
            System.out.println("========欢迎登录网络通讯系统========");
            System.out.println("\t\t1.登录系统");
            System.out.println("\t\t9.退出系统");
            System.out.print("请输入你的选择：");
            switch (Utility.readString(1)) {
                case "1":
//                输入账号密码
                    System.out.print("请输入账号：");
                    String userid = Utility.readString(50);
                    System.out.print("请输入密码：");
                    String userpsw = Utility.readString(50);
//                        根据校验结果判断是否登录成功
                    if (userClientService.login(userid, userpsw)) {//登录成功
//                            进入二级菜单页面
                        System.out.println("========欢迎您， " + userid + " 登录成功========");
                        while (loop) {
                            System.out.println("========网络通信系统二级菜单(" + userid + ")========");
                            System.out.println("\t\t1.显示在线用户列表");
                            System.out.println("\t\t2.群发消息");
                            System.out.println("\t\t3.私聊消息");
                            System.out.println("\t\t4.发送文件");
                            System.out.println("\t\t9.退出系统");
                            System.out.print("请输入你的选择：");
                            switch (Utility.readString(1)) {
                                case "1":
                                    userClientService.getOnlineUsers();
                                    break;
                                case "2":
                                    userClientService.sendAllMessage();
                                    break;
                                case "3":
                                    userClientService.sendOneMessage();
                                    break;
                                case "4":
                                    userClientService.sendFileToOne();
                                    break;
                                case "9":
                                    userClientService.logout();
                                    loop = false;
                                    break;
                            }
                        }
                    } else {
                        System.out.println("登录失败");
                    }
                    break;
                case "9":
                    System.out.println("退出系统");
                    loop = false;//结束一级菜单循环
                    break;
            }
        }
    }
}
